

export const isFloat = (rule, value, callback) => {
  if (!value) {
    callback();
  } else {
    var reg = /^-?\d{1,10}(?:\.\d{1,2})?$/;
    if (reg.test(value)) {
      callback();
    } else {
      callback(new Error("数字格式:0-9999999999或小数点后可加1到2位"));//如:1 或1.8 或1.85
    }
  }
};

export const isNumber = (rule, value, callback) => {
  if (/\D/.test(value)) {
    callback(new Error('请输入数字类型'));
  } else {
    callback();
  }
};

export const isTelOrFax = (rule, value, callback) => {
  if (!value) {
    callback();
  } else {
    const reg = /^(\d{3,4}-)?\d{7,8}$/;
    const isTel = reg.test(value);
    if (value.length < 10 || value.length > 13 || !isTel ) {//判断传真字符范围是在10到13
      callback(new Error("格式如:0376-12345678"));
    } else {
      callback();
    }
  }
};

export const checkPhone = (rule, value, callback) => {
  if (!value) {
    callback();
  } else {
    var reg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
    if (reg.test(value)) {
      callback();
    } else {
      callback(new Error("请输入正确手机号码"));
    }
  }
};
